cimport cython
cimport numpy as np
import numpy as np

cdef extern from "/data/xianjieyang/code/github/libtorch/ali_tf_conform/asr_pywarp.h" nogil:
    int asr_init_model(char* model_path)
    void asr_asyn_decode(long *stDecodertmp)
    void asr_alloc_stdecoder(long *stDecodertmp, char *model_path, char *model, char *lang)
    void asr_free_stdecoder(long *stDecodertmp)
    int asr_input_online(long *stDecodertmp, const char *wavdata, int wavlen)
    void asr_input_end(long *stDecodertmp)
    void asr_reset(long *stDecodertmp)
    void asr_gethyps_num(long *stDecodertmp, int *hyp_num)
    void asr_gethyps(long *stDecodertmp,int maxnum,int *hyps, int *hyp_num)
    void asr_alloc_stVAD(long *stVADtmp, char *model_path)
    void asr_vad_reset(long *stVADtmp)
    void asr_free_stVAD(long *stVADtmp)
    int asr_vad_input(long *stVADtmp, const char *wavdata, int wavlen, char end)

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef int warp_asr_init_model(char *model_path) noexcept nogil:
    with nogil:
        return asr_init_model(model_path)

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_asyn_decode(long[:] stDecodertmp) noexcept nogil:
    with nogil:
        asr_asyn_decode(&stDecodertmp[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_alloc_stdecoder(long[:] stDecodertmp, char *model_path, char *model, char *lang) noexcept nogil:
    with nogil:
        asr_alloc_stdecoder(&stDecodertmp[0], model_path, model, lang)

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef int warp_asr_input_online(long[:] stDecodertmp,  const char[:] wavdata, int wavlen) noexcept nogil:
    with nogil:
        return asr_input_online(&stDecodertmp[0], &wavdata[0], wavlen)

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_input_end(long[:] stDecodertmp) noexcept nogil:
    with nogil:
        asr_input_end(&stDecodertmp[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_reset(long[:] stDecodertmp) noexcept  nogil:
    with nogil:
        asr_reset(&stDecodertmp[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_free_stdecoder(long[:] stDecodertmp) noexcept nogil:
    with nogil:
        asr_free_stdecoder(&stDecodertmp[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_gethyps_num(long[:] stDecodertmp, int[:] hyp_num):
    asr_gethyps_num(&stDecodertmp[0], &hyp_num[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_gethyps(long[:] stDecodertmp, int max_num, int[:] hyps, int[:] hyp_num):
    asr_gethyps(&stDecodertmp[0], max_num, &hyps[0], &hyp_num[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_alloc_stVAD(long[:] stVADtmp, char *model_path) noexcept nogil:
    with nogil:
        asr_alloc_stVAD(&stVADtmp[0], model_path)

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_free_stVAD(long[:] stVADtmp) noexcept nogil:
    with nogil:
        asr_free_stVAD(&stVADtmp[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef void warp_asr_vad_reset(long[:] stVADtmp) noexcept nogil:
    with nogil:
        asr_vad_reset(&stVADtmp[0])

@cython.boundscheck(False)
@cython.wraparound(False)
cpdef int warp_asr_vad_input(long[:] stVADtmp, const char[:] wavdata, int wavlen, char end) noexcept nogil:
    with nogil:
        return asr_vad_input(&stVADtmp[0], &wavdata[0], wavlen, end)
